from multiprocessing import Queue, Process
from random import randint
from time import sleep


def request(q):
    for i in range(20):
        x = randint(0, 100)
        y = randint(0, 100)
        # 满了就会阻塞
        q.put((x, y))


def handle(q):
    while True:
        sleep(0.5)
        try:
            x, y = q.get(timeout=3)
        except:
            break
        else:
            print('%d+%d=%d' % (x, y, x + y))


if __name__ == "__main__":
    q = Queue(5)
    p1 = Process(target=request, args=(q,))
    p2 = Process(target=handle, args=(q,))
    p1.start()
    p2.start()
    p1.join()
    p2.join()
